package com.holystone.splunk.utils;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * Copyright (c) 2017, HOLYSTONE Technologies, Inc.
 * All right reserved.
 *
 * @author huyan
 * @date 2017/12/6
 * @desc:
 */
public class PropertiesUtils {

    private static Properties prop = null;

    public static String readValue(String key) {
        if (prop == null || prop.size() == 0) {
            InputStreamReader is = null;
            try {
                prop = new Properties();
                is = new InputStreamReader(PropertiesUtils.class.getClassLoader().getResourceAsStream("/log_search/log_search.properties"), "UTF-8");
                prop.load(is);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        String value = prop.getProperty(key.trim());
        return value;
    }
}
